jQuery.extend({
getURLParam: function(strParamName){
	  var strReturn = "";
	  var strHref = window.location.href;
	  var bFound=false;
	  
	  var cmpstring = strParamName + "=";
	  var cmplen = cmpstring.length;

	  if ( strHref.indexOf("?") > -1 ){
	    var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	    var aQueryString = strQueryString.split("&");
	    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	      if (aQueryString[iParam].substr(0,cmplen)==cmpstring){
	        var aParam = aQueryString[iParam].split("=");
	        strReturn = aParam[1];
	        bFound=true;
	        break;
	      }
	      
	    }
	  }
	  if (bFound==false) return null;
	  return strReturn;
	}
});

$(document).ready(function()
{
	var storeId = $.getURLParam("storeId");
    jQuery.getJSON( "getArticles.php?storeid=" + storeId, onResult );
   //$(content).html("Full response: " +storeId);  
}
);

function onResult(obj)
{
  var content="";
  var divTag;
  for(var i=0;i< obj.length;i++)
  {
	  divTag = "<div>" + getReview(obj[i]) + "</div>";
	  //console.log(divTag);
	  $('body').append(divTag);
	  //content += divTag;
  }
}

function getReview(obj)
{
	var content="<p>";
	
	if(obj.title != null && obj.title != undefined)
	{
		content += "<div class='reviewTitle'>" + obj.title + "</div>";	
	}
	
	if(obj.articleUrl != null && obj.articleUrl != undefined)
	{
		content += "<span width='50' style='width:150px;word-wrap:break-word'>";
		content += "<a href='"+ obj.articleUrl + "' class='reviewLink' target='_blank'>" + obj.articleUrl + "</a></span><br>";	
	}
	
	if(obj.icon != null && obj.icon != undefined)
	{
		content += "<img src='"+ obj.icon + "'></img>";	
	}
	
	if(obj.image != null && obj.image != undefined)
	{
		content += "<img src='"+ obj.image + "'></img>";	
	}
	
	if(obj.excerpt != null && obj.excerpt != undefined)
	{
		content += "<span class='reviewArticle'>" + obj.excerpt + "</span>";
	}
	
	
	content += "</p>";
	return content;
}